class Model8:  # 基础数据模型
    进出口 = None
    海关编码 = None
    商品名称 = None
    月度 = None
    企业编码 = None
    企业名称 = None
    收发货地 = None
    数量 = None
    计量单位 = None
    金额 = None  # 金额(USD)
    单价 = None
    产销国 = None
    中转国 = None
    报关口岸 = None
    贸易方式 = None
    运输方式 = None
    电话 = None
    传真 = None
    邮编 = None
    电子邮箱 = None
    联系人 = None
    企业性质 = None
    地址 = None
    省市 = None

    def get_sql__(self):
        props = dir(self)
        count = len(props)
        sql_str = "insert into %s (" % self.get_table_name__()
        sql_val = " values ("
        for i in range(0, count):
            prop = props[i]
            if "__" in prop:
                continue
            sql_str += prop
            sql_val += "'" + str(getattr(self, prop, None)).replace("'", "''") + "'"
            if i < count - 1:
                sql_str += ","
                sql_val += ","
        sql_str += ")" + sql_val + ")"
        return sql_str

    def get_create_table_sql__(self):
        sql = "create table %s (" % self.get_table_name__()
        props = dir(self)
        count = len(props)
        for i in range(0, count):
            prop = props[i]
            if "__" in prop:
                continue
            sql += prop + " nvarchar(800)"
            if i < count - 1:
                sql += ","
        sql += ")"
        return sql

    @staticmethod
    def get_table_name__():
        return None


class ImportModel(Model8):  # 进口数据模型

    @staticmethod
    def get_table_name__():
        return "import_data"


class ExportModel(Model8):  # 出口数据模型

    @staticmethod
    def get_table_name__():
        return "export_data"
